package com.xzx.redisstudy;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.BinaryJedisCluster;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

/**
 * 集群测试
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2021-06-01 11:10 下午
 */
public class ClusterDemo {
    public static void main(String[] args) {
        Set<HostAndPort> nodes = new HashSet<>();
        // 这里连接一个能成功的原因是，会自动切换到目标插槽的机器执行读写操作
        nodes.add(new HostAndPort("127.0.0.1", 7001));
        JedisCluster jedisCluster = new JedisCluster(nodes, 2000, 2000, 5, "123456", new GenericObjectPoolConfig());

        jedisCluster.set("k1", "v1");
        System.out.println(jedisCluster.get("k1"));
    }
}
